import java.awt.print.*;
import java.awt.*;

public class Printer
    implements Printable {
	
	Canvas frame;
	
	public Printer (Canvas frameToPrint)
	{
		frame = frameToPrint;
	}

  public int print(Graphics g, PageFormat pf, int page)
      throws PrinterException {

	  if (page > 0) {
	        return NO_SUCH_PAGE;
	    }

	    Graphics2D g2d = (Graphics2D)g;
	    g2d.translate(pf.getImageableX(), pf.getImageableY());

	    // Print the entire visible contents of a
	    // java.awt.Frame.
	    frame.printAll(g);

	    return PAGE_EXISTS;
  }
}
